package bsw.wode.interceptor;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;

import bsw.wode.action.AuthEnabled;
import bsw.wode.config.ActionConstant;

public class AuthInterceptor implements Interceptor {

	private static final long serialVersionUID = -4752821948154640998L;

	public void destroy() {
	}

	public void init() {
	}

	public String intercept(ActionInvocation invocation) throws Exception {
		Action action = (Action) invocation.getAction();
		if (action instanceof AuthEnabled) {
			if (!((AuthEnabled) action).hasPermission()) {
				return ActionConstant.NOPERMISSION;
			}
		}
		return invocation.invoke();
	}

}